package com.wdb.common.util;

import com.wdb.common.base.BaseEntity;
import com.wdb.common.configurer.subject.SubjectContext;
import com.wdb.common.constant.Constant;
import org.springframework.util.Assert;

import java.util.Date;

/**
 * util for base domain subclass
 *
 * @author shiyu.long
 */
public abstract class BaseEntityUtils {
    /**
     * fill create info
     *
     * @param entity subclass of base domain
     */
    public static void fillCreateInfo(BaseEntity entity) {
        //assert
        Assert.notNull(entity, "current domain for insert can not be null");
        entity.setDeleted(Constant.N);
        entity.setCreated(new Date());
        entity.setCreateUserId(SubjectContext.getSubject());
    }

    /**
     * fill update info
     *
     * @param entity subclass of update info
     */
    public static void fillUpdateInfo(BaseEntity entity) {
        //assert
        Assert.notNull(entity, "current domain for update can not be null");
        entity.setModified(new Date());
        entity.setUpdateUserId(SubjectContext.getSubject());
    }
}
